/**
 * https://leetcode.cn/submissions/detail/361487125
 * 209. 长度最小的子数组
 * medium, 叶佳豪 2024.9.1
 * 滑动窗口
 */

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int i=0,sum=0,num=nums.size()+1;
        for(int j=0;j<nums.size();j++){
            sum+=nums[j];
            while(sum>=target){
                num=min(num,j-i+1);
                sum-=nums[i];
                i++;
            }
        }
        return num > nums.size() ? 0 : num;
    }
};